package cn.aylog.controller;

import cn.aylog.pojo.User;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {

    private ObjectMapper mapper = new ObjectMapper();

    @RequestMapping("/login")
    @ResponseBody
    // public String login(User user) {
    // public String login(String name, String pwd) {
    //     User user = new User();
    //     user.setName(name);
    //     user.setPwd(pwd);
    //     System.out.println(user);
    //     return "login";
    // }
    public String login(@RequestParam("name") String a, @RequestParam("pwd") String b) {
        User user = new User();
        user.setName(a);
        user.setPwd(b);
        System.out.println(user);
        return "login";
    }

    // 使用Restful风格接口
    @RequestMapping("/loginV2/{name}/{pwd}")
    @ResponseBody
    public String loginV2(@PathVariable String name, @PathVariable String pwd) {
        User user = new User();
        user.setName(name);
        user.setPwd(pwd);
        System.out.println(user);
        return "login";
    }

    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login";
    }
}
